package cn.wwk.notification.search.controller;

import cn.wwk.notification.common.result.Result;
import cn.wwk.notification.search.constants.UserIndex;
import cn.wwk.notification.search.doc.IndexParams;
import cn.wwk.notification.search.service.CommonIndexService;
import cn.wwk.notification.search.service.UserDocService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 用户的索引库操作
 * @author wwk
 */
@RestController
@RequestMapping("/index/user")
@Slf4j
public class UserIndexController {

    @Autowired
    private CommonIndexService commonIndexService;

    @Autowired
    private UserDocService userDocService;

    @PostMapping("/create")
    public Result createIndex(@RequestBody IndexParams index) throws IOException {
        System.out.println(index);
        index.setDSL(UserIndex.user);
        return commonIndexService.createIndex(index);
    }

    /**
     * 批量将User数据库的内容，添加进索引库
     * */
    @PostMapping("/add")
    public Result add2Index(String indexName) throws IOException {

        return  userDocService.bulkAddToIndex();
    }

}
